package com.dollar.juc.threadLocal.simpleDateFormat;

import java.text.ParseException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 *
 */
public class TestSafeSimpleDateFormat {
    public static void main(String[] args) {
        SafeSimpleDateFormat safeSimpleDateFormat = new SafeSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 创建线程池，最好直接new ThreadPoolExecutor，而不是用Executors工具类
        // ExecutorService threadPool = Executors.newCachedThreadPool();
        ExecutorService threadPool = new ThreadPoolExecutor(
                5, 50, 0L,
                TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(100)
        );

        List<String> dates = Arrays.asList(
                "2019-02-21 15:47:01",
                "2018-03-22 16:46:02",
                "2017-04-23 17:45:03",
                "2016-05-24 18:44:04",
                "2015-06-25 19:43:05",
                "2014-07-26 20:42:06",
                "2013-08-27 21:41:07",
                "2012-09-28 22:40:08",
                "2011-10-29 23:39:09"
        );

        for (String date : dates) {
            threadPool.execute(() -> {
                try {
                    System.out.println(safeSimpleDateFormat.parse(date));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            });
        }
    }
}


